Ext.define('DragonApp.view.white.AccountForm', {
    extend: 'Ext.window.Window',
    alias: 'widget.accountform',

    requires: ['DragonApp.view.pub.combobox.MultiServer'],
    layout: 'center',

    closable: true,
    modal: true,
    height: 200,
    width: 500,
    items: [{
        modelValidation: true,
        xtype: 'form',
        padding: 10,
        layout: {
            type: 'fit',
            align: 'stretch'
        },
        items: [{
            title: '白名单信息',
            xtype: 'fieldset',
            layout: 'anchor',
            width: 480,
            padding: '15 20 15 20',
            defaults: {
                afterLabelTextTpl: DragonApp.util.String.required,
                xtype: 'textfield',
                msgTarget: 'side',
                labelWidth: 85,
                anchor: '100%'
            },
            items: [{
                fieldLabel: '白名单ID',
                xtype: 'hiddenfield',
                name: 'id'
            }, {
                emptyText: '多人请用英文逗号分隔',
                fieldLabel: '白名单账号',
                allowBlank: false,
                name: 'account',
                listeners: {
                    'change': function(field, newValue, oldValue) {
                        var noempty = DragonApp.util.String.removeAllSpace(newValue);
                        var newFieldValue = noempty.replace(/[、，;；:：\|\\/]/g, ",");
                        field.setValue(newFieldValue);
                    }
                },
                validator: function(fieldValue) {

                    //空元素处理
                    var arr = fieldValue.split(',');

                    //重复判断
                    if (DragonApp.util.Array.repeatTest(arr)) {
                        return ('提示: 字段存在重复元素');
                    }

                    //长度判断
                    for (var i = 0; i < arr.length; i++) {
                        if (7 != (String(arr[i])).length) {
                            return ('提示: ' + String(arr[i]) + ' 账号长度不正确');
                        }
                        if (!DragonApp.util.Regular.Uid.test(arr[i])) {
                            return ('提示: 字段格式 ' + String(arr[i]) + ' 不正确');
                        }
                    }

                    arr = arr.noEmpty();

                    this.setValue(arr.join(','));
                    return true;
                }
            }, {
                fieldLabel: '适用服务器',
                xtype: 'multiservercombo',
                allowBlank: false,
                name: 'server'
            }, {
                xtype: 'hiddenfield',
                fieldLabel: '类型',
                value: 'account',
                name: 'type'
            }]
        }]
    }],
    dockedItems: [{
        xtype: 'toolbar',
        dock: 'bottom',
        ui: 'footer',
        layout: {
            pack: 'end',
            type: 'hbox'
        },
        items: [{
            xtype: 'button',
            text: '取消',
            iconCls: 'x-fa fa-times',
            handler: 'onCancel'
        }, {
            xtype: 'button',
            text: '保存',
            itemId: 'savebtn_accountform',
            iconCls: 'x-fa fa-check',
            handler: 'onSave'
        }]
    }]
});